<?php

/* 已测试成功
 * 
  $material_id;材料id
  $price;交易材料价格
  $trade_date;交易时间
  $trade_number;交易数量
  $statement判断条件
 * 
 */

header('Content-Type: text/html; charset=utf-8');
include dirname(__FILE__) . '/../../class/Material_record.php';
$id = $_POST['id'];
$material_id = $_POST['material_id'];
$price = $_POST['price'];
$trade_number = $_POST['number'];
$statement = $_POST['statement'];


switch ($statement) {
    case 'add':
        if (Material_record::add_a_record($material_id, $price, $trade_number)) {
            echo 1;
        } else {
            echo 0;
        }
        break;
    case 'delete':

        if (Material_record::del_a_record($id)) {
            echo 1;
        } else {
            echo 0;
        }
        break;
    case 'update':

        $rs = Material_record::get_Material_record_id($id);
        $rs->material_id = $material_id;
        $rs->price = $price;
        $rs->trade_number = $trade_number;

        if ($rs->update()) {
            echo 1;
        } else {
            echo 0;
        }
        break;
    default :
        echo 0;
        break;
}